package com.dd.stack.mybatisplus.pojo.req;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dd.stack.common.util.param.PageParams;
import com.dd.stack.mybatisplus.pojo.DO.DataObjectDO;
import com.dd.stack.mybatisplus.pojo.params.DataObjectQueryParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/1/9 0:59
 * @Description DataObject查询请求类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("DataObject查询请求类")
public class DataObjectQueryReq {
    @ApiModelProperty("分页请求参数")
    private PageParams pageParams;
    @ApiModelProperty("DataObject查询请求参数")
    private DataObjectQueryParams dataObjectQueryParams;

    // 构建查询条件
    public LambdaQueryWrapper<DataObjectDO> buildLambdaQueryWrapper() {
        LambdaQueryWrapper<DataObjectDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        // DO查询参数
        if (dataObjectQueryParams!= null) {
            if (dataObjectQueryParams.getIntValueMin()!= null) {
                lambdaQueryWrapper.ge(DataObjectDO::getIntValue, dataObjectQueryParams.getIntValueMin());
            }
            if (dataObjectQueryParams.getIntValueMax()!= null) {
                lambdaQueryWrapper.le(DataObjectDO::getIntValue, dataObjectQueryParams.getIntValueMax());
            }
            if (dataObjectQueryParams.getLongValueMin()!= null) {
                lambdaQueryWrapper.ge(DataObjectDO::getLongValue, dataObjectQueryParams.getLongValueMin());
            }
            if (dataObjectQueryParams.getLongValueMax()!= null) {
                lambdaQueryWrapper.le(DataObjectDO::getLongValue, dataObjectQueryParams.getLongValueMax());
            }
            if (dataObjectQueryParams.getDoubleValueMin()!= null) {
                lambdaQueryWrapper.ge(DataObjectDO::getDoubleValue, dataObjectQueryParams.getDoubleValueMin());
            }
            if (dataObjectQueryParams.getDoubleValueMax()!= null) {
                lambdaQueryWrapper.le(DataObjectDO::getDoubleValue, dataObjectQueryParams.getDoubleValueMax());
            }
            if (dataObjectQueryParams.getStringValue()!= null) {
                lambdaQueryWrapper.like(DataObjectDO::getStringValue, dataObjectQueryParams.getStringValue());
            }
            if (dataObjectQueryParams.getJsonValue()!= null) {
                lambdaQueryWrapper.like(DataObjectDO::getJsonValue, dataObjectQueryParams.getJsonValue());
            }
            if (dataObjectQueryParams.getLocalDateTimeValueStart()!= null) {
                lambdaQueryWrapper.ge(DataObjectDO::getLocalDateTimeValue, dataObjectQueryParams.getLocalDateTimeValueStart());
            }
            if (dataObjectQueryParams.getLocalDateTimeValueEnd()!= null) {
                lambdaQueryWrapper.le(DataObjectDO::getLocalDateTimeValue, dataObjectQueryParams.getLocalDateTimeValueEnd());
            }
        }
        return lambdaQueryWrapper.orderByAsc(DataObjectDO::getId);
    }
}

